package ifrn.pds.siem.banco;

import ifrn.pds.funcoes.User;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class ListarUser implements ListarUserDAO {
	public Banco banco;

	public ListarUser() {
		banco = new Banco();
	}

	public ArrayList<User> listarUsuarios() {
		try {
			User contasUsuario = null;
			ArrayList<User> todosUsuarios = new ArrayList<User>();
			if (!banco.isConnected())
				banco.conectar();
			Statement statement = banco.conexao.createStatement();
			ResultSet rs = statement
					.executeQuery("select * from usuario");
			while (rs.next()) {
				String user = rs.getString("logon");
				String password = rs.getString("senha");
				String nome = rs.getString("nome");
				int permissao = rs.getInt("permissao");
				contasUsuario = new User(user, password, nome, permissao);
				todosUsuarios.add(contasUsuario);
			}

			return todosUsuarios;
		} catch (SQLException e) {
			return null;
		}

	}

}
